package weaver.interfaces.jjy.duss.hr;

import com.sap.mw.jco.JCO;
import com.weaver.general.BaseBean;
import weaver.interfaces.jjy.duss.util.SAPComMehtod;
import weaver.interfaces.jjy.duss.util.SAPConnPool;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: ecology-9-demo
 * @description: ${description}
 * @author: Dusongsong
 * @create: 2019-12-07
 */
/* User: wkj
 *"合同续签"接口，入参：
 *          JIEKNO      HR015
 *          IV_PERNR    06090075
 *          PT0016  PERNR	员工号	06090075
 *          PT0016	CTTYP	续签合同类型	10
 *          PT0016  BEGDA   开始日期	20191201
 *          //PT0016	ENDDA	结束日期	20221130
 *          PT0016	CTEDT	续签合同终止日期	20221130
 *          PT3211  PERNR	员工号	06090075
 *          PT3211	ZHR_QXM	续签合同期限（月）	36
 *          PT3211	ZHR_WRKPL	续签合同签订单位	家家悦
 *          PT3211	ZHR_HTMB	续签劳动合同模板	01
 *          PT3211	ZHR_BDLX	续签合同变动类型	20
 * */
public class HR015 {
    public Map execute(Map<String, String> map) {

        SAPConnPool SAPConn = new SAPConnPool();
        JCO.Client myConnection = SAPConn.getConnection();
        JCO.Function bapi = SAPConn.excuteBapi("ZFM_HR_PERNR");

        JCO.ParameterList input = bapi.getImportParameterList();//输入参数和结构处理
        JCO.ParameterList inputtable = bapi.getTableParameterList();//输入表的处理

        //入参为字段
        input.setValue("HR015", "JIEKNO");                   //HR接口标识：HR009入职&返聘接口
        input.setValue(map.get("IV_PERNR"), "IV_PERNR");

        JCO.Structure stu1 = input.getStructure("PS0001");
        stu1.setValue(map.get("PERNR"), "PERNR");           //员工号
        stu1.setValue(map.get("PLANS"), "PLANS");           //岗位
        stu1.setValue(map.get("ZHR_GWXL"), "ZHR_GWXL");     //职务序列
        stu1.setValue(map.get("ZHR_ZW"), "ZHR_ZW");         //职务名称
        stu1.setValue(map.get("ZHR_ZWC"), "ZHR_ZWC");       //职务簇

        //入参为表
        JCO.Table t1 = inputtable.getTable("PT0016");
        t1.appendRow();

        t1.setValue(map.get("CTTYP"), "CTTYP");         //续签合同类型
        t1.setValue(map.get("CTBEG"), "CTBEG");         //开始日期
        t1.setValue(map.get("CTEDT"), "CTEDT");         //续签合同终止日期

        JCO.Table t2 = inputtable.getTable("PT3211");
        t2.appendRow();
        t2.setValue(map.get("PERNR"), "PERNR");         //员工号
        t2.setValue(map.get("ZHR_QXM"), "ZHR_QXM");           //ZHR_QXM	续签合同期限（月）
        t2.setValue(map.get("ZHR_WRKPL"), "ZHR_WRKPL");      //续签合同签订单位
        t2.setValue(map.get("ZHR_HTMB"), "ZHR_HTMB");          //续签劳动合同模板
        t2.setValue(map.get("ZHR_BDLX"), "ZHR_BDLX");          //续签合同变动类型

        JCO.Table t3528 = inputtable.getTable("PT3528");
        t3528.appendRow();

        t3528.setValue(map.get("DEPTN"), "DEPTN");         //续签合同类型
/*

        //执行函数
        myConnection.execute(bapi);
        JCO.ParameterList out = bapi.getExportParameterList();//输出参数和结构处理
        JCO.ParameterList Table00 = bapi.getTableParameterList();//输出表的处理

        //返回处理结果以及日志
        String[] strs = {"EV_OUTPUT","PS0000","PS0001"};
        //SAPConn.SAPreturnS(strs, out);

        String[] tabs = {"PT0016", "PT3211","PT3528"};
        //SAPConn.SAPreturnT(tabs, Table00);
        Map<String, String> mapreturn = SAPComMehtod.SAPreturnS(strs, out, tabs, Table00);

*/

        //执行函数
        myConnection.execute(bapi);
        JCO.ParameterList out = bapi.getExportParameterList();//输出参数和结构处理
        JCO.ParameterList Table00 = bapi.getTableParameterList();//输出表的处理

        //返回处理结果以及日志
        Map<String, String> mapreturn = new HashMap<>();
        JCO.Structure stu = out.getStructure("EV_OUTPUT");
        mapreturn.put("flag",(String) stu.getValue("ZFLAG"));
        mapreturn.put("message",(String) stu.getValue("ZMESG"));
        if("E".equals(mapreturn.get("flag"))){
            //遍历
            BaseBean baseBean = new BaseBean();
            String structure = baseBean.getPropValue("SAPAllTable","structure");//所有结构
            String[] structures = structure.split(",");
            String table = baseBean.getPropValue("SAPAllTable","table");//所有表
            String[] tables = table.split(",");
            mapreturn = SAPComMehtod.SAPreturnS(structures, out, tables, Table00);
            baseBean.writeLog("SAP返回结果"+mapreturn.toString());
        }
        JCO.releaseClient(myConnection);
        return mapreturn;
    }







}
